#include <iostream>
using namespace std;

class User
{
public:
    User(string sname="NoName"):m_name(sname)
    {
        s_total++ ;
		m_uid = s_total ;
    }

    int getUserID() const
    {
        return m_uid;
    }
	
    string getUserName() const
    {
        return m_name;
    }
	
    static int getTotoalUserCount( )
    {
        return s_total;
    }
    ~User()
	{
		s_total-- ;
	}
	
private:
    int m_uid;
	string m_name;
    static int s_total; 
};

int User::s_total = 0;  //静态变量初始化

void fun( )
{
	User tmpu("Mary");
	cout<<tmpu.getUserID()<<"\t"<<tmpu.getUserName()<<endl;
	cout << "IN fun:there are " << User::getTotoalUserCount() << " user(s) totally" << endl;
}	

int main()
{
    User usr1("Tom");
    cout<<usr1.getUserID()<<"\t"<<usr1.getUserName()<<endl;
	cout << "IN main1 :there are " << User::getTotoalUserCount() << " user(s) totally" << endl;
	User usrs[3]={User("Candy"),User("Jack")};
	for(int i=0;i<3;i++)
	{
		cout<<usrs[i].getUserID()<<"\t"<<usrs[i].getUserName()<<endl;
	}
	cout << "IN main2 :there are " << User::getTotoalUserCount() << " user(s) totally" << endl;
	fun();
	cout << "IN main3 :there are " << User::getTotoalUserCount() << " user(s) totally" << endl;
}